home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / CHASSIS_ / WRITEFRO.C < prev   
Text File  |  1992-05-14  |  1KB  |  34 lines

  1. /************************************************************************************/
  2. /*    WriteFromTE                                                                        */
  3. /*                                                                                    */
  4. /*    Writes to open file from existing TextEdit record                                */
  5. /************************************************************************************/
  6.  
  7. #include "MyHeaders.h"
  8.  
  9. long WriteFromTE(int pathRefNum, TEHandle hTE)
  10. {
  11.     OSErr    writeErr;                            /* return from I/O routines            */
  12.     long    bytesWrite = 0;                        /* total of bytes returned            */
  13.     Ptr        beginP;                                /* ptr to begin of temp I/O area    */
  14.  
  15.     CursorSelect (NIL, NIL, watchCursor);        /* set watch cursor                    */
  16.     
  17.     writeErr = SetFPos (pathRefNum, fsFromStart, 0);    /* positn file ptr to begin    */
  18.     
  19.     bytesWrite = (**hTE).teLength;                /* number of bytes to write            */
  20.     beginP = *(**hTE).hText;                    /* pointer to text                    */
  21.  
  22.     writeErr = FSWrite (pathRefNum, &bytesWrite, beginP);    /* write to the file    */
  23.     if (writeErr == noErr)
  24.         SetEOF (pathRefNum, bytesWrite);                    /* set new EOF            */
  25.     else
  26.         {
  27.         ParamText (&workReply.fName,"","","");            /* set text as file name    */
  28.         PlaceAlert (140);                                /* position the alert        */
  29.         StopAlert (140, NIL);                            /* show the alert            */
  30.         }
  31.     
  32.     return bytesWrite;                            /* return total no of bytes            */
  33. }
  34.